package com.taptech.doufu.util;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupWindow;

import com.taptech.doufu.R;
import com.taptech.doufu.bean.UserBean;

public class CommentUtil {



	public static void showReplyDialog(final Activity activity,
			final UserBean data, final InputDialogHandCallback callback) {
		final PopupWindow window = new PopupWindow();
		window.setFocusable(true);
		window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
		window.setWidth(LayoutParams.MATCH_PARENT);
		window.setHeight(LayoutParams.WRAP_CONTENT);
		window.setBackgroundDrawable(new ColorDrawable());
		window.setOutsideTouchable(true);
		View baseView = activity.getLayoutInflater().inflate(
				R.layout.diaobao_component_input_dialog, null);
		final EditText text = (EditText) baseView
				.findViewById(R.id.input_dialog_text);
		if (data != null) {
			text.setHint("回复" + data.getName() + ":");
		}
		((InputMethodManager) activity
				.getSystemService(Context.INPUT_METHOD_SERVICE))
				.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
		text.setFocusable(true);
		Button btn = (Button) baseView.findViewById(R.id.input_dialog_btn);
		btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				String message = text.getText().toString();
				if (message != null && !message.equals("")) {					
					callback.handleComplete(message);	
					window.dismiss();
				}

			}
		});

		window.setContentView(baseView);
		window.showAtLocation(baseView, Gravity.BOTTOM, 0, 0);

	}

	public interface InputDialogHandCallback {
		void handleComplete(String message);
	}
}
